<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>1-同源策略</title>
  <link rel="stylesheet" href="http://127.0.0.1:8081/static/css/a.css">
  <script src="http://127.0.0.1:8081/static/js/a.js"></script>
</head>
<body>
  <img src="http://127.0.0.1:8081/static/img/a.png" alt="">
  <button id="btn">发ajax请求</button>
  <script>
    document.querySelector('#btn').onclick = () => {
      const xhr = new XMLHttpRequest()
      xhr.open('GET', 'http://127.0.0.1:8081/origin-server')
      xhr.send()
      xhr.onreadystatechange = () => {
        if (xhr.readyState===4) {
          if (xhr.status>=200 && xhr.status<=299) {
            alert('请求成功: ' + xhr.responseText)
          } else {
            alert('请求失败 status=' + xhr.status)
          }
        }
      }
    }
  </script>
</body>
</html>